package com.appkubes.mall.admin.application.customer.address.controller;

import com.appkubes.cloud.config.params.paramValid.ParamValid;
import com.appkubes.common.Response;
import com.appkubes.mall.admin.application.customer.address.entity.vo.AddAddressVO;
import com.appkubes.mall.admin.application.customer.address.entity.vo.AddressListVO;
import com.appkubes.mall.admin.application.customer.address.entity.vo.ModifyAddressVO;
import com.appkubes.mall.admin.application.customer.address.service.CustomerAddressService;
import com.appkubes.mall.core.controller.BaseMallCustomerController;
import com.appkubes.mall.core.entity.MallCustomerAddress;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Rongjie
 * @Date: 2020/3/4
 * @Description:
 */
@Api(tags = "渠道用户地址")
@RestController
@RequestMapping("/customer/address")
public class CustomerAddressController extends BaseMallCustomerController {

    @Autowired
    CustomerAddressService customerAddressService;

    @ApiOperation("添加地址")
    @PostMapping("/addAddress")
    public Response addAddress(@ParamValid AddAddressVO addAddress){
        MallCustomerAddress customerAddress = new MallCustomerAddress();
        BeanUtils.copyProperties(addAddress,customerAddress);
        customerAddressService.save(customerAddress);
        return Response.success();
    }


    @ApiOperation("修改地址")
    @PostMapping("/modifyAddress")
    public Response modifyAddress(ModifyAddressVO modifyAddress){
        MallCustomerAddress customerAddress = new MallCustomerAddress();
        BeanUtils.copyProperties(modifyAddress,customerAddress);
        customerAddressService.updateById(customerAddress);
        return Response.success();
    }

    @ApiOperation("地址列表")
    @PostMapping("/addressList")
    public Response addressList(AddressListVO addressListVO){
        MallCustomerAddress customerAddress = new MallCustomerAddress();
        customerAddress.setCustomerKey(addressListVO.getCustomerKey());

        IPage<MallCustomerAddress> addressIPage = customerAddressService.selectPageByEntity(customerAddress,
                addressListVO.getPage(),
                addressListVO.getSize());

        return Response.success(addressIPage);
    }
}
